// 内部迭代器
const each = (array, callback) => {
    for (let i = 0; i < array.length; i++) {
        callback(i, array[i]);
    }
}

each( ['a', 'b', 'c'], (i, n) => {
    console.log(`${i}: ${n}`);
})

console.log();

// 中止迭代器
const suspendableEach = (array, callback) => {
    for (let i = 0; i < array.length; i++) {
        if (callback(i, array[i]) === false) {
            break;
        }
    }
}

suspendableEach([1, 2, 3, 4, 5], (i, n) => {
    if (n > 4) {
        return false;
    }
    console.log(`${i}: ${n}`);
})